/* 储存订单管理-回款管理-基础设置相关api */

import { ajaxService } from '@/utils/request';
import { getToken } from '@/utils/auth';
import axios from 'axios';

const env = import.meta.env;
let baseURL = env.VITE_ORDER_URL;
// let baseURL = env.VITE_API_BASE_URL;

// 获取回款编号数据
export function GetReturnedCodeInfo() {
  return ajaxService({
    url: '/order/receivable/num',
    method: 'get',
    baseURL,
  });
}

// 修改回款编号
export function PostReturnedCodeInfo(data: any) {
  return ajaxService({
    url: '/client/numSet',
    method: 'post',
    baseURL,
    data,
  });
}

// 获取回款类型设置数据
export function GetReturnedTypeInfo() {
  return ajaxService({
    url: '/order/receivable/account/type/set',
    method: 'get',
    baseURL,
  });
}

// 删除回款类型设置数据
export function DelReturnedTypeInfo(data: any) {
  return ajaxService({
    url: '/order/receivable/account/type/set',
    method: 'delete',
    baseURL,
    data,
  });
}

// 新增回款类型设置数据
export function PostReturnedTypeInfo(data: any) {
  return ajaxService({
    url: '/order/receivable/account/type/set',
    method: 'post',
    baseURL,
    data,
  });
}

// 获取账号设置数据
export function GetAccountInfo(data: any) {
  return ajaxService({
    url: '/order/receivable/account/set',
    method: 'get',
    baseURL,
    data,
  });
}

// 根据id获取对应的账户
export function GetReceivableAccount(params: any) {
  return ajaxService({
    url: '/order/receivable/account',
    method: 'get',
    baseURL,
    params,
  });
}

// 新增账号设置数据
export function PostAccountInfo(data: any) {
  return ajaxService({
    url: '/order/receivable/account/set',
    method: 'post',
    baseURL,
    data,
  });
}

// 删除一条账号设置数据
export function DelAccountInfo(params: any) {
  return ajaxService({
    url: '/order/receivable/account/set',
    method: 'delete',
    baseURL,
    params,
  });
}

// 获取发票类型数据
export function GetSetInvoiceInfo(params?: any) {
  return ajaxService({
    url: '/order/receivable/account/invoice/set',
    method: 'get',
    baseURL,
    params,
  });
}

// 添加发票类型数据
export function PostSetInvoiceInfo(data: any) {
  return ajaxService({
    url: '/order/receivable/account/invoice/set',
    method: 'post',
    baseURL,
    data,
  });
}

// 新增发票类型
export function PostInvoiceInfo(data: any) {
  return ajaxService({
    url: '/order/invoice/record',
    method: 'post',
    baseURL,
    data,
  });
}

// 编辑发票类型
export function putInvoiceInfo(data: any) {
  return ajaxService({
    url: '/order/invoice/record',
    method: 'put',
    baseURL,
    data,
  });
}

// 删除发票类型
export function delInvoiceInfo(params: any) {
  return ajaxService({
    url: '/order/invoice/record',
    method: 'delete',
    baseURL,
    params,
  });
}

// 获取发票类型
export function getInvoiceInfo(params?: any) {
  return ajaxService({
    url: '/order/invoice/record',
    method: 'get',
    baseURL,
    params,
  });
}

// 获取回款类型
export function getCollectionInfo(params: any) {
  return ajaxService({
    url: '/order/collection/record',
    method: 'get',
    baseURL,
    params,
  });
}

// 新增回款类型
export function PostCollectionInfo(data: any) {
  return ajaxService({
    url: '/order/collection/record',
    method: 'post',
    baseURL,
    data,
  });
}

// 编辑回款类型
export function putCollectionInfo(data: any) {
  return ajaxService({
    url: '/order/collection/record',
    method: 'put',
    baseURL,
    data,
  });
}

// 删除回款类型
export function delCollectionInfo(params: any) {
  return ajaxService({
    url: '/order/collection/record',
    method: 'delete',
    baseURL,
    params,
  });
}

// 导出回款
export async function GetCollectionDeriveExcel(name?: string) {
  const res: any = await axios({
    method: 'get',
    url: '/order/collection/derive',
    baseURL,
    headers: {
      'Content-Type': 'multipart/form-data;charset=UTF-8',
      'Authorization': `${getToken()}`,
    },
    responseType: 'blob',
    // data: file,
  });
  const file = new Blob([res.data], { type: 'application/xlsx' });
  const changeUrl = window.webkitURL.createObjectURL(file);
  let downloadElement: any = document.createElement('a');
  downloadElement.download = (name || 'test') + '.xlsx';
  downloadElement.href = changeUrl;
  downloadElement.click();
  downloadElement = undefined;
  window.URL.revokeObjectURL(changeUrl);
}

// 新增或修改回款编号设置
export function postCollectionNumSet(params: any) {
  return ajaxService({
    url: '/order/collection/record/numSet',
    method: 'post',
    params,
    baseURL,
  });
}
